// 引入axios二次封装
import request from '@/utils/request'
// 引入spu相关的接口类型
import {SpuModel, SpuListModel, SpuPageListModel, SpuPageListParamsModel, BaseSaleAttrListModel, SpuImageListModel, SpuSaleAttrListModel} from './model/spuModel'
// 定义枚举类型的接口地址
enum Api {
  // 获取基础销售属性对象数组的接口地址
  GetBaseSaleAttrList='/admin/product/baseSaleAttrList',
  // 根据spuId移除对应的spu对象的接口地址
  DeleteSpuInfoById='/admin/product/deleteSpu',
  // 根据关键词获取spu对象数组的接口地址
  GetSpuListByKeyword='/admin/product/findSpuInfoByKeyword',
  // 根据spuId获取对应的spu对象的接口地址
  GetSpuInfoById='/admin/product/getSpuInfo',
  // 根据spuId 数组 获取spu对象数组的接口地址
  GetSpuListByIds='/admin/product/inner/findSpuInfoBySpuIdList',
  // 新增spu对象的接口地址
  AddSpuInfo='/admin/product/saveSpuInfo',
  // 更新spu对象的接口地址
  UpdateSpuInfo='/admin/product/updateSpuInfo',
  // 根据页码 每页条数 三级分类id 获取 spu对象数组数据的接口地址
  GetSpuPageList='/admin/product',
  // 根据spuId 获取spu图片对象数组的接口地址
  GetSpuImageListById='/admin/product/spuImageList',
  // 根据spuId 获取spu销售属性对象数组的接口地址
  GetSpuSaleAttrListById='/admin/product/spuSaleAttrList'
}

// 获取基础销售属性对象数组的接口函数
export const getBaseSaleAttrListApi = () => request.get<any, BaseSaleAttrListModel>(Api.GetBaseSaleAttrList)
// 根据spuId移除对应的spu对象的接口函数
export const deleteSpuInfoByIdApi = (spuId: number) => request.delete<any, null>(Api.DeleteSpuInfoById + `/${spuId}`)
// 根据关键词获取spu对象数组的接口函数
export const getSpuListByKeywordApi = (keyword: string) => request.get<any, SpuListModel>(Api.GetSpuListByKeyword +  `/${keyword}`)
// 根据spuId获取对应的spu对象的接口函数
export const getSpuInfoByIdApi = (spuId: number) => request.get<any, SpuModel>(Api.GetSpuInfoById + `/${spuId}`)
// 根据spuId 数组 获取spu对象数组的接口函数
export const getSpuListByIdsApi = (ids: number[]) => request.post<any, SpuListModel>(Api.GetSpuListByIds, ids)
// 新增spu对象的接口函数
export const addSpuInfoApi = (spuInfo: SpuModel) => request.post<any, null>(Api.AddSpuInfo, spuInfo)
// 更新spu对象的接口函数
export const updateSpuInfoApi = (spuInfo: SpuModel) => request.post<any, null>(Api.UpdateSpuInfo, spuInfo)
// 根据页码 每页条数 三级分类id 获取 spu对象数组数据的接口函数
export const getSpuPageListApi = ({page, limit, category3Id}: SpuPageListParamsModel) => request.get<any, SpuPageListModel>(Api.GetSpuPageList + `/${page}/${limit}`, {
  params: {category3Id}
})

// 新增/修改 spu对象的接口函数
export const addOrUpdataSpuInfoApi = (spuInfo: SpuModel) => spuInfo.id? updateSpuInfoApi(spuInfo): addSpuInfoApi(spuInfo)

// 根据spuId 获取spu图片对象数组的接口函数
export const getSpuImageListByIdApi = (spuId: number) => request.get<any, SpuImageListModel>(Api.GetSpuImageListById + `/${spuId}`)
// 根据spuId 获取spu销售属性对象数组的接口函数
export const getSpuSaleAttrListByIdApi = (spuId: number) => request.get<any, SpuSaleAttrListModel>(Api.GetSpuSaleAttrListById + `/${spuId}`)

